﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.city;
using Trans.session;

namespace Trans.customer
{
    public partial class Manage_customer : Form
    {
        public Manage_customer()
        {
            InitializeComponent();
        }

        private void Manage_customer_Load(object sender, EventArgs e)
        {
            this.tb_customerTableAdapter.Fill(this.dataSet.tb_customer);
            
        }

        private void bt_save_Click(object sender, EventArgs e)
        {
            try
            {
                tb_customerBindingSource.EndEdit();
                tb_customerTableAdapter.Update(dataSet.tb_customer);
                this.Close();
                MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("出错啦"+ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tb_customerBindingSource.CancelEdit();
            this.Close();
        }

        private void dataGridViewX1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
        }

        private void gv_customer_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            session.Color_Const.set_gv_color(gv_customer);
        }

        private void gv_customer_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void bt_city_Click(object sender, EventArgs e)
        {
            select_city form = new select_city();
            if (form.ShowDialog() == DialogResult.OK)
            {
                DataRowView r = (DataRowView)tb_customerBindingSource.Current;
                r["city_id"] = form.Id;
                lable_city.Text = form.Name_s;
            }
        }

        private void gv_customer_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            tb_cityTableAdapter1.FillById(dataSet.tb_city, (int)gv_customer.Rows[e.RowIndex].Cells["c_cityid"].Value);
            lable_city.Text = (string)dataSet.tb_city.Rows[0]["name"];
        }
    }
}
